package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduLiveWatchRecordMapper;
import com.zenith.edu.po.domain.EduLiveWatchRecord;
import com.zenith.edu.po.dto.EduLiveWatchRecordDTO;
import com.zenith.edu.po.vo.EduLiveWatchRecordVO;
import com.zenith.edu.service.EduLiveWatchRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduLiveWatchRecordServiceImpl extends ServiceImpl<EduLiveWatchRecordMapper, EduLiveWatchRecord> implements EduLiveWatchRecordService {
    
    @Override
    public EduLiveWatchRecordVO createLiveWatchRecord(EduLiveWatchRecordDTO dto) {
        EduLiveWatchRecord liveWatchRecord = new EduLiveWatchRecord();
        BeanUtils.copyProperties(dto, liveWatchRecord);
        this.save(liveWatchRecord);
        
        EduLiveWatchRecordVO vo = new EduLiveWatchRecordVO();
        BeanUtils.copyProperties(liveWatchRecord, vo);
        return vo;
    }
    
    @Override
    public EduLiveWatchRecordVO getLiveWatchRecordById(Long id) {
        EduLiveWatchRecord liveWatchRecord = this.getById(id);
        if (liveWatchRecord == null) {
            return null;
        }
        
        EduLiveWatchRecordVO vo = new EduLiveWatchRecordVO();
        BeanUtils.copyProperties(liveWatchRecord, vo);
        return vo;
    }
    
    @Override
    public EduLiveWatchRecordVO updateLiveWatchRecord(EduLiveWatchRecordDTO dto) {
        EduLiveWatchRecord liveWatchRecord = new EduLiveWatchRecord();
        BeanUtils.copyProperties(dto, liveWatchRecord);
        this.updateById(liveWatchRecord);
        
        EduLiveWatchRecordVO vo = new EduLiveWatchRecordVO();
        BeanUtils.copyProperties(liveWatchRecord, vo);
        return vo;
    }
    
    @Override
    public boolean deleteLiveWatchRecord(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduLiveWatchRecordVO> getLiveWatchRecordList() {
        List<EduLiveWatchRecord> liveWatchRecordList = this.list();
        return liveWatchRecordList.stream().map(liveWatchRecord -> {
            EduLiveWatchRecordVO vo = new EduLiveWatchRecordVO();
            BeanUtils.copyProperties(liveWatchRecord, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}